#ifndef LOG_MANAGER_CPP_H
#define LOG_MANAGER_CPP_H

#include <sstream>
#include <string>
#include <mutex>

// 定义日志等级
enum class LogLevel
{
    DEBUG,
    INFO,
    WARN,
    ERROR,
    FATAL
};

class LogManager
{
public:
    LogManager(const std::string &logFilePath = "log_manager.log", size_t maxSize = 20 * 1024 * 1024);
    ~LogManager();
    void setLogFile(const std::string &logFilePath = "log_manager.log");
    void setMaxSize(size_t maxSize = 20 * 1024 * 1024);
    void setConsoleLogLevel(LogLevel level);
    void setFileLogLevel(LogLevel level);
    void log_debug(const char *format, ...);
    void log_info(const char *format, ...);
    void log_warn(const char *format, ...);
    void log_error(const char *format, ...);
    void log_fatal(const char *format, ...);

private:
    std::string logFilePath;
    size_t maxSize;
    LogLevel consoleLogLevel;
    LogLevel fileLogLevel;
    std::mutex logMutex;
    void log(LogLevel level, const char *format, va_list args);
    std::string getLevelString(LogLevel level);
    void ensureFileSize();
    std::string formatMessage(const char *format, va_list args);
    std::string getCurrentDateTime();
};

#endif //LOG_MANAGER_CPP_H
